package com.hy.controller;

import com.alibaba.fastjson.JSONObject;
import com.hy.service.FaceService;
import com.hy.utils.HY_Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * 人脸识别Controller
 * @Author: 是奕靜吖
 */
@RestController
@RequestMapping("/hy-frontuser-consumer/face")
public class faceController {

    //人脸 - 业务
    @Autowired
    private FaceService fs;

    /**
     * 人脸绑定
     * @param image_Bast64
     * @return
     */
    @PostMapping("/faceRegister.action")
    public HY_Result faceRegistration(@RequestBody String image_Bast64) throws IOException {
        JSONObject json = JSONObject.parseObject(image_Bast64);
        return fs.faceRegistration(new StringBuffer(json.get("image_Bast64").toString()));
    }

    /**
     * 人脸登录
     * @param image_Bast64 为 JSON 格式{"image_Bast64":"iVBORw0KGgoA...}
     * @return
     */
    @PostMapping("/faceLogin.action")
    public HY_Result faceLogin(@RequestBody String image_Bast64) throws IOException {
        JSONObject json = JSONObject.parseObject(image_Bast64);
        return fs.faceLogin(new StringBuffer(json.get("image_Bast64").toString()));
    }

}
